define(['jquery'], () => {
    function fn() {
        //当前模块实现某项功能的代码
        //加入购物车

        $.get('./data/goods.json', 'json').then(function (res) {
            res = res.slice(0, 40)

            let ul = document.querySelector('.paging_list')
            ul.addEventListener('click', function (e) {
                e = e || window.event
                let target = e.target
                // console.log(target.dataset.id)
                let id1 = target.dataset.id
                let pro = res.find(function (item) {
                    return id1 == item.goods_id
                })
                let arr = JSON.parse(localStorage.getItem('shangping')) || []
                if (arr.length == 0) {
                    pro.cart_number++
                    arr.push(pro)
                } else {
                    // console.log(arr)
                    let p = arr.findIndex(function (item) {
                        return id1 == item.goods_id
                    })
                    if (p == -1) {
                        pro.cart_number++
                        arr.push(pro)
                    } else {
                        arr[p].cart_number++
                    }
                }

                localStorage.setItem('shangping', JSON.stringify(arr))

            })

        })


    }
    //返回函数名称，将函数调用的控制权交给main.js文件中
    return {
        fn: fn
    }
})